package com.heima.article.controller.v1;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.AuthorService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/author")
@Api(value = "作者信息管理API",tags = "作者信息管理API")
public class AuthorController {
    @Autowired
    AuthorService authorService;

    @ApiOperation("根据ApUser id查询作者信息")
    @GetMapping("/findByUserId/{id}")
    public ResponseResult findByUserId(@PathVariable("id") Integer id){
       return  ResponseResult.okResult(authorService.getOne(
               Wrappers.<ApAuthor>lambdaQuery()
               .eq(ApAuthor::getId,id)
       ));
    }

    @ApiOperation("保存作者信息")
    @PostMapping("/save")
    public ResponseResult asveAuthor(@RequestBody ApAuthor apAuthor){
        return ResponseResult.okResult(authorService.save(apAuthor));
    }
}
